package com.mh.server;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author MH
 * @since 2021-10-27
 */
public class Request {

    private final String method;
    private final String url;
    private final InputStream inputStream;

    public Request(InputStream inputStream) throws IOException {
        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String requestLine = new String(bytes).split("\n")[0];
        String[] requestLineArr = requestLine.split(" ");
        this.method = requestLineArr[0];
        this.url = requestLineArr[1];
        this.inputStream = inputStream;

    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public String getMethod() {
        return method;
    }

    public String getUrl() {
        return url;
    }

    @Override
    public String toString() {
        return "Request{" +
                "method='" + method + '\'' +
                ", url='" + url + '\'' +
                '}';
    }
}
